package com.yhx.utils;

import com.yhx.pojo.Checkitem;
import com.yhx.pojo.Ordersetting;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ExcelUtils {
    public static List<Ordersetting> ExcelgetList(File file) throws IOException, InvalidFormatException {
        List list = new ArrayList<>();
        //创建一个工作簿
        XSSFWorkbook workbook = new XSSFWorkbook(file);
        //获取工作簿的表
        XSSFSheet sheet = workbook.getSheetAt(0);
        //看表中有多少条数据
        int rows = sheet.getPhysicalNumberOfRows();
        //遍历将表格中的数据存入list
        for (int i = 0; i < rows-1; i++) {
            //获取行
            XSSFRow row = sheet.getRow(i + 1);
            //得到传递过来的时间
            Date date = row.getCell(0).getDateCellValue();
            //得到传递过来的数据Number
            double numericCellValue = row.getCell(1).getNumericCellValue();
            int value = Double.valueOf(numericCellValue).intValue();
            list.add(new Ordersetting(0,date,value,0));
        }
        return list;
    }

    public static List<Checkitem> ExcelgetList2(File file) throws IOException, InvalidFormatException {
        List<Checkitem> list = new ArrayList<>();
        //创建一个工作簿
        XSSFWorkbook workbook = new XSSFWorkbook(file);
        //获取工作簿的表
        XSSFSheet sheet = workbook.getSheetAt(0);
        //看表中有多少条数据
        int rows = sheet.getPhysicalNumberOfRows();
        //遍历将表格中的数据存入list
        for (int i = 0; i < rows-1; i++) {
            //获取行
            XSSFRow row = sheet.getRow(i + 1);
            //得到传递过来的时间
            double numericCellValue1 = row.getCell(0).getNumericCellValue();
            int value = Double.valueOf(numericCellValue1).intValue();

            //得到传递过来的数据Number
            String value1= row.getCell(1).getStringCellValue();
            String value2 = row.getCell(2).getStringCellValue();
            double numericCellValue = row.getCell(3).getNumericCellValue();
            String value3 = String.valueOf(numericCellValue);
            String value4 = row.getCell(4).getStringCellValue();
            //得到传递过来的时间
            double value5 = row.getCell(5).getNumericCellValue();
            String value6 = row.getCell(6).getStringCellValue();
            String value7 = row.getCell(7).getStringCellValue();
            String value8 = row.getCell(8).getStringCellValue();
            list.add(new Checkitem(value,value1,value2,value3,value4,value5,value6,value7,value8));
        }
        return list;
    }
}
